<?php

defined('IN_SCHOOL') or die();

/*{TranslateTagBegin}*/
class control_friendlink extends base_control{

	public function __construct() {
	
		parent::__construct();
		
	}
	
	public function do_index() {
		$this->check_gid100();
		
		$edit_msg = '';
		
		$content = core::gpc('content', 'P');
		$content = htmlspecialchars_decode($content);
		if(!empty($content)) {
			$tmp = $save = array();
			$ress = explode("\n", $content);
			foreach($ress as $k=>$v) {
				if(empty($v)) continue;
				$exp = explode('|' , $v);
				if(2 == count($exp)) {
					$tmp['name'] = $exp[0];
					$tmp['link'] = $exp[1];
					$save[] = $tmp;
				}
			}
			if(!empty($save)) {
				$edit_msg = '设置失败';
				if($this->kv->set('jy_friendlink', $save)) {
					$edit_msg = '设置成功';
				}
			}
		}
		
		$jy_friendlinks = $this->kv->get('jy_friendlink');
		$jy_friendlinks = ($jy_friendlinks == false) ? array() : $jy_friendlinks;

		$content = '';
		foreach($jy_friendlinks as $v) {
			$content .= $v['name'].'|'.$v['link']."\n";
		}
		$content = core::htmlspecialchars($content);
		$this->tpl->assign('edit_msg',$edit_msg);
		$this->tpl->assign('content',$content);
		$this->tpl->display('friendlink_manage.tpl');
	}
	
	private function check_gid100() {
		$gid = $this->user->user_groupid();
		if($gid != 100)
			$this->message('权限不足','index.php');
	}

}
/*{TranslateTagEnd}*/

?>